package com.aop.annotation;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Set;

public class CombinationInterceptor implements MethodInterceptor {

    private static final Logger LOGGER = LoggerFactory.getLogger(CombinationInterceptor.class);
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Method method = methodInvocation.getMethod();
        if (method.isAnnotationPresent(CombinationAnnotation.class)) {
            CombinationAnnotation annotation = method.getAnnotation(CombinationAnnotation.class);
            //CombinationAnnotation mergedAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CombinationAnnotation.class);
            TextAnnotation mergedAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, TextAnnotation.class);
            LOGGER.info("==============annotation:{}==============",annotation);
            LOGGER.info("==============mergedAnnotation:{}==============",mergedAnnotation);


        }
        return methodInvocation.proceed();
    }
}
